import { Collection, EntitySchema } from '@mikro-orm/core';
import { Users } from './Users';

export class ChatRooms {
  id!: string;
  creatorId?: string;
  ownerId?: string;
  setting?: any;
  topic?: string;
  chatRoomMembers = new Collection<Users>(this);
}

export const ChatRoomsSchema = new EntitySchema({
  class: ChatRooms,
  properties: {
    id: { primary: true, type: 'string', columnType: 'bigint' },
    creatorId: {
      type: 'string',
      columnType: 'bigint',
      nullable: true,
      index: 'creator_id_foreign_key',
    },
    ownerId: {
      type: 'string',
      columnType: 'bigint',
      nullable: true,
      index: 'owner_id_foreign_key',
    },
    setting: { type: 'any', columnType: 'json', nullable: true },
    topic: { type: 'string', length: 255, nullable: true },
    chatRoomMembers: {
      reference: 'm:n',
      entity: () => Users,
      pivotTable: 'chat_room_members',
      joinColumn: 'room_id',
      inverseJoinColumn: 'user_id',
    },
  },
});
